# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-cucumber-core
pkgver=11.1.0
pkgrel=1
pkgdesc="Core library for the Cucumber BDD app"
arch=(any)
url='https://github.com/cucumber/cucumber-ruby-core'
license=(MIT)
depends=(ruby-cucumber-gherkin ruby-cucumber-messages ruby-cucumber-tag-expressions)
makedepends=(ruby-rake ruby-rspec ruby-unindent)
checkdepends=(ruby-simplecov)
options=(!emptydirs)
source=(https://github.com/cucumber/cucumber-ruby-core/archive/v$pkgver/$pkgname-$pkgver.tar.gz)
sha256sums=('253fbfa67e755c9c6d85e7624a1926283c1b40376a2531bb0448ba016a711ed1')

prepare() {
  cd cucumber-ruby-core-$pkgver
  sed -i -r -e '/rubocop/d' -e 's|~>|>=|g' cucumber-core.gemspec
  sed -i '/[rR]ubo[cC]op/d' Rakefile
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd cucumber-ruby-core-$pkgver
  gem build cucumber-core.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    cucumber-core-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd cucumber-ruby-core-$pkgver
  GEM_HOME="tmp_install/$_gemdir" rake spec spec:slow
}

package() {
  cd cucumber-ruby-core-$pkgver
  cp -a tmp_install/* "$pkgdir"/
  install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
}
